package basic.study.wantOffer.chapter6;

/**
 * @ClassName Problem66
 * @Description 构建乘积数组
 * @Company inspur
 * @Author Kevin
 * @Date 2020/6/15 11:15
 * @Version 1.0
 */
public class Problem66 {
    public int[] multiply(int[] A) {
        if (A == null || A.length < 2) {
            return null;
        }
        int[] B = new int[A.length];
        B[0] = 1;
        for(int i = 1; i < A.length; i++) {
            B[i] = B[i-1] * A[i-1];
        }
        int temp = 1;
        for (int i = A.length-1; i >= 0; i--) {
            temp *= A[i+1];
            B[i] *= temp;
        }
        return B;
    }
}
